package com.ruoyi.controller;

import com.ruoyi.server.MqttService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class MqttTestController {

    @Resource
    private MqttService mqttService;

    @GetMapping("/mqtt/test")
    public String testMqtt() {
        String topic = "testtopic/A"; // 主题（与订阅主题一致）
        String message = "{\"msg\":\"Hello from RuoYi!\"}"; // JSON 消息
        mqttService.publish(topic, message);
        return "MQTT 消息已发送";
    }
}